package com.homework.ch02;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/23
 * @Description:
 */
class Student{
    String name;
}
public class Test6 {
    public static void main(String[] args) {
        //创建流对象
        Stream<String> s2=Stream.of("hello");
        Stream<Integer> s3= Stream.of(20);
        System.out.println("s2:"+s2);
        System.out.println("s2=:"+s2.count());//终端操作潜台词:关闭流
        //forEach也是终端操作，也会关闭流
        s3.forEach(System.out::println);
        //多元素创建流
        Stream<String> s4=Stream.of("one","two","three","four");
        s4.forEach(System.out::println);

        //多个学生放到流中打印输出地址值
        Student s=new Student();
        Stream.of(s,s,s,new Student(),new Student()).forEach(System.out::println);
        //使用数组作为数据源获得流对象
        String[] arr={"a","b","c","d","e"};
        Stream<String> s5=Stream.of(arr);
        s5.forEach(System.out::println);//s5流关闭
        //System.out.println(Arrays.stream(arr).count());
        //使用集合作为数据源获取流对象
        List<String> list=Arrays.asList("a","b","c","d");
        Stream<String> s7=list.stream();

        //并行流 paraller Stream
        Stream<String> s8=list.parallelStream();
        s8.forEach(System.out::println);


    }
}
